import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a[]=new int[20];
        for (int i=0;i<20;i++){
            a[i] = sc.nextInt();
        }
        int index_max=0;
        int max=a[0];
        int index_min=0;
        int min=a[1];
        for (int i=1;i<20;i++){
            if (a[i]>max){
                index_max=i;
                max=a[i];
            }else if (a[i]<min){
                index_min=i;
                min=a[i];
            }
        }
        System.out.println("max="+max+",min="+min);
        int tem=a[index_max];
        a[index_max]=a[index_min];
        a[index_min]=tem;
        for (int j=0;j<5;j++){
            int i=0;
            for (;i<3;i++){
                System.out.printf("%5s",a[j*4+i]);
            }
            System.out.printf("%5s",a[j*4+i]);
            System.out.println();
        }

    }
}
